<?php
ini_set("max_execution_time","10000");
my_component_load('testing' , false);
my_component_load('paging' , false);   
my_component_load('data_setting', false);
my_component_load('xl_builder' , false);   
my_component_load('list_kalender' , false);   
my_component_load('pr_formula_rapel' , false);   
my_component_load('pr_rapel' );
$task = isset($_GET['task']) ? $_GET['task'] : "";  
$id = isset( $_GET['id'] ) ? $_GET['id']:  0;
$sumber_id = isset( $_GET['sumber_id'] ) ? $_GET['sumber_id']:  0;
$ref_id = isset( $_GET['ref_id'] ) ? $_GET['ref_id']:  0;
$rapel_id= isset( $_GET['rapel_id'] ) ? $_GET['rapel_id']:  0; 
$tanggal = isset($_GET['tanggal']) ? $_GET['tanggal'] : "";  
$value = isset($_GET['value']) ? $_GET['value'] : "";  

$komponen_id = isset( $_GET['komponen_id'] ) ? $_GET['komponen_id']:  0;
$karyawan_id = isset( $_GET['karyawan_id'] ) ? $_GET['karyawan_id']:  0;

$modulname = "Penggajian _BN_ Rapel";
if($_SERVER['REQUEST_METHOD'] == "POST" ):
	switch($task){
		case "rapel_periode_create_page":
			$validatepost = rapel_periode_validate($rapel_id, $id);
			if($validatepost){
				$errors = message_multi_error($validatepost);
				$content = $errors;
				$content .= form_rapel_periode_create($rapel_id, $id);
				generate_my_web($content,"","plain.php");
				exit; 
			}else {
				rapel_periode_submit($rapel_id, $id); 
				$content =  "Updated";
				generate_my_web($content,"","plain.php");
				exit;
			}
			break; 				
		case "rapel_pengecualian_page":
			submit_pengecualian( $komponen_id , $rapel_id); 
			$content =  "Updated";
				generate_my_web($content,"","plain.php");
			exit;
			break;
		case "rapel_komponen_create_page":
			$validatepost = rapel_komponen_validate($rapel_id, $id);
			
			if($validatepost){
				$errors = message_multi_error($validatepost);
				$content = $errors;
				$content .= form_rapel_komponen_create($rapel_id, $id);
				generate_my_web($content,"","plain.php");
				exit; 
			}else {
				rapel_komponen_submit($rapel_id, $id); 
				$content =  "Updated";
				generate_my_web($content,"","plain.php");
				exit;
			}
			break; 		
	}
else: 

	if($task =="list_periode"){
		load_facebox_script();
		$pagename = $modulname." _BN_ Periode";
		$view =  list_periode($rapel_id);	
	}elseif($task == "rapel_pengecualian"){
		$title= (($id > '0' ) ?  "Perubahan " : "Tambah")." Data pengecualian rapel" ;
		facebox_page('index.php?com=pr_rapel&task=rapel_periode_create_page&rapel_id='.$rapel_id.'&id='.$id , $title , 260	); 
	}elseif($task == "rapel_periode_create"){
		$title= (($id > '0' ) ?  "Perubahan " : "Tambah")." Data Periode Rapel" ;
		facebox_page('index.php?com=pr_rapel&task=rapel_pengecualian_page&komponen_id='.$komponen_id.'&rapel_id='.$rapel_id.'&id='.$id , $title , 260	); 
	}elseif($task == "rapel_pengecualian_page"){ 
		$content = form_pengecualian($id);
		generate_my_web($content,"","plain.php");
		exit; 
	}elseif($task == "rapel_periode_create_page"){ 
	 
		$content  = form_rapel_periode_create($rapel_id, $id) ;
		generate_my_web($content,"","plain.php");
		exit; 
	}elseif($task == 'kalkulasi'){  
		rapel_proses_komponen( $rapel_id); 
		my_direct($_SERVER['HTTP_REFERER']);	
	}elseif($task == 'proses_rinci_komponen'){  
		rapel_proses_komponen($komponen_id,$rapel_id);
		my_direct($_SERVER['HTTP_REFERER']);	
	}elseif($task == 'delete_rapel_periode'){ 
		delete_rapel_periode($id);
		my_direct($_SERVER['HTTP_REFERER']);	
		
	}elseif($task =="list_komponen_detail"){
		load_facebox_script();
		$komponen = my_get_data_by_id('pr_komponen_gaji','komponen_gaji_id',$komponen_id);
		$pagename = $modulname." _BN_ Komponen _BN_ ".$komponen['nama_komponen_gaji'] ;
		$view =  list_komponen_rapel_detail($komponen_id , $rapel_id);
		
	}elseif($task =="list_komponen"){
		load_facebox_script();
		$pagename = $modulname." _BN_ Komponen";
		$view =  list_komponen($rapel_id);	
	}elseif($task =="insert_komponen_auto"){
		insert_komponen_auto($rapel_id);	
		my_direct($_SERVER['HTTP_REFERER']);			
	}elseif($task == "rapel_komponen_upload"){
		$title= "Upload komponen rapel" ;
		facebox_page('index.php?com=pr_rapel&task=rapel_komponen_upload_page&rapel_id='.$rapel_id.'&id='.$id , $title , 260	); 
	}elseif($task == "rapel_komponen_create"){
		$title= (($id > '0' ) ?  "Perubahan " : "Tambah")." Data Komponen Rapel" ;
		facebox_page('index.php?com=pr_rapel&task=rapel_komponen_create_page&rapel_id='.$rapel_id.'&id='.$id , $title , 260	); 
	}elseif($task == "rapel_komponen_upload_page"){ 
		$content  = form_rapel_komponen_upload($rapel_id) ;
		generate_my_web($content,"","plain.php");
		exit;
	}elseif($task == "rapel_komponen_create_page"){ 
		$content  = form_rapel_komponen_create($rapel_id, $id) ;
		generate_my_web($content,"","plain.php");
		exit; 

	}elseif($task == 'excel_list_komponen'){ 
 
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment;filename=rapel_all_komponen.xls");
		echo  excel_list_komponen($rapel_id);
		exit;

	}elseif($task == 'excel_rapel'){ 
		$komponen = my_get_data_by_id('pr_komponen_gaji','komponen_gaji_id',$komponen_id);
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment;filename=rapel_".str_replace(" ","_",$komponen['nama_komponen_gaji']).'_'.rand().".xls");
		echo excel_rapel_report( $komponen_id , $rapel_id);
		exit;
	}elseif($task == 'delete_rapel_komponen'){ 
		delete_rapel_komponen($id);
		my_direct($_SERVER['HTTP_REFERER']);
	}elseif($task =='loading_rapel'){
		$title="Kalkulasi rapel seluruh karyawan";
		facebox_page('index.php?com='.$_GET['com'].'&task=kalkulasi_rapel_all_page&rapel_id='.$rapel_id.'&p='.rand(0,999999) , $title , 120	); 
	}elseif($task =='kalkulasi_rapel_all_page'){  
		$content = page_kalkulasi_rapel($rapel_id); 
		generate_my_web($content,"","plain.php");
		exit;
	//END ADD LOADING	
		
	}elseif($task =='kalkulasi_rapel_all'){
		ini_set("max_execution_time","10000");
		header("Cache-Control: no-cache, must-revalidate"); 
		rapel_proses_komponen( $rapel_id); 
		//$query = "UPDATE opsi_seting SET value='0' WHERE name='kalkulasi'";
		//my_query($query);
		echo button_icon( 'check2.png' ,'')."<br/>Done !!";
		exit;
		//my_direct($_SERVER['HTTP_REFERER']);			
	}else{
		$pagename = $modulname;
		load_facebox_script();
		$view =  list_rapel();
	}
	generate_my_web($view , $pagename );	
endif; 

